"""版本一GenericAPIView"""
# from rest_framework.generics import GenericAPIView
# from rest_framework.response import Response
# from meiduo_admin.serializer.user_serializer import *
# from meiduo_admin.pages import MyPage
# from meiduo_admin.serializer.permission_serializer import *
# from meiduo_admin.serializer.admin_serializer import *
#
#
# # 请求方式： GET /meiduo_admin/permission/admins/
# class AdminView(GenericAPIView):
#     serializer_class = AdminPermSerializer
#     queryset = User.objects.filter(is_staff=True)
#     pagination_class = MyPage
#
#     """获取所有管理用户"""
#     def get(self, request):
#         admin = self.get_queryset()
#         page = self.paginate_queryset(admin)
#         if page:
#             page_serializer = self.get_serializer(page, many=True)
#             return self.get_paginated_response(page_serializer.data)
#         serializer = UserSerializer(admin, many=True)
#         return Response(serializer.data)
#
#     def post(self, request):
#         admin_obj = request.data
#         serializer = UserSerializer(data=admin_obj)
#         serializer.is_valid(raise_exception=True)
#         serializer.save()
#         return Response(serializer.data, status=201)
#
#
# # 请求方式： GET /meiduo_admin/permission/groups/simple/
# class AdminSimpleView(GenericAPIView):
#     serializer_class = ContentTypeSerializer
#     queryset = ContentType.objects.all()
#
#     """管理员权限类别"""
#     def get(self, request):
#         permission_type = self.get_queryset()
#         serializer = self.get_serializer(permission_type, many=True)
#         return Response(serializer.data)
#
#
# # 请求方式： GET /meiduo_admin/permission/admins/(?P<pk>\d+)/
# class AdminObjView(GenericAPIView):
#     serializer_class = AdminPermSerializer
#     queryset = User.objects.filter(is_staff=True)
#
#     """获取单一数据"""
#     def get(self, request, pk):
#         admin_obj = self.get_object()
#         serializer = self.get_serializer(admin_obj)
#         return Response(serializer.data)
#
#     def put(self, request, pk):
#         admin_obj = self.get_object()
#         serializer = UserSerializer(instance=admin_obj, data=request.data)
#         serializer.is_valid(raise_exception=True)
#         serializer.save()
#         return Response(serializer.data)
#
#     def delete(self, request, pk):
#         admin_obj = self.get_object()
#         admin_obj.delete()
#         return Response({})

"""版本二ModelViewSet"""

from rest_framework.viewsets import ModelViewSet
from rest_framework.generics import ListAPIView
from meiduo_admin.pages import MyPage
from meiduo_admin.serializer.permission_serializer import *
from meiduo_admin.serializer.admin_serializer import *


# 请求方式： GET /meiduo_admin/permission/admins/
class AdminView(ModelViewSet):
    serializer_class = AdminPermSerializer
    queryset = User.objects.filter(is_staff=True)
    pagination_class = MyPage


# 请求方式： GET /meiduo_admin/permission/groups/simple/
class AdminSimpleView(ListAPIView):
    serializer_class = ContentTypeSerializer
    queryset = ContentType.objects.all()
